package jm.mq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import jm.mq.utils.RabbitMQUtils;

import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * @Description 生产者，发送五条消息。
 * @date 2022/3/7 14:30
 */
public class Producer4 {
    private static final String LONG_QUEUE = "pre_val";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMQUtils.getChannel();
        channel.queueDeclare(LONG_QUEUE,false,false,false,null);
        Scanner scanner = new Scanner(System.in);
        int i = 0;
        while (scanner.hasNext()){
            i++;
            String msg = scanner.next() + i;
            channel.basicPublish("",LONG_QUEUE, null,msg.getBytes(StandardCharsets.UTF_8));
            System.out.println("发送消息：'" + msg + "'成功");
        }
    }
}
